package com.jboltai.resource.vdb;

import com.jboltai.capability.vdb.JBoltVDB;
import com.jboltai.config.JBoltAIConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.concurrent.ConcurrentHashMap;

public class VDBResourceCenter {
    private static final Logger LOGGER = LoggerFactory.getLogger(JBoltAIConfig.LOGGER_NAME);
    /**
     * function 资源
     */
    private static final ConcurrentHashMap<String, VDBResource> RESOURCES = new ConcurrentHashMap<>();


    /**
     * 注册vdb资源
     * @param resource
     * @return
     */
    public static VDBResource register(VDBResource resource) {
        VDBResource prev = RESOURCES.putIfAbsent(resource.getId(), resource);
        if (prev != null && prev != resource) {
            throw new RuntimeException("已注册id为[" + resource.getId() + "]的Function资源，不可重复注册");
        }
        return resource;
    }

    /**
     * 取消注册某资源
     * @param vdbId
     */
    public static void unregister(String vdbId) {
        RESOURCES.remove(vdbId);
        JBoltVDB.remove(vdbId);
    }

    /**
     * 根据id获取资源
     * @param vdbId
     * @return
     */
    public static VDBResource get(String vdbId) {
        return RESOURCES.get(vdbId);
    }


    /**
     * 获取资源数量
     * @return
     */
    public static int getResourceCount() {
        return RESOURCES.size();
    }



}
